from public.tools import *
from public.action import *
from public.testDATE import *

from selenium.webdriver.common.keys import Keys
testCase="DBshop010_退货管理处理退货"

#前台产生退货订单

# "1.点击销售管理退货管理。
firefox=openB(adminurl)
adminlogin(firefox)
menu2(firefox,"销售管理","退货管理")

s=Select(firefox.find_element_by_xpath("//td[2]/select"))
s.select_by_value("1")
firefox.find_element_by_xpath("//tr/td[text()='等待处理']/following-sibling::td/a[1]").click()
s=firefox.find_element_by_xpath("//div[2]/dl/dd[1]").text
time.sleep(4)
l="^"
r="$"
orderID=reGetString(s,l,r)
print(orderID)
# "1.点击处理退货，退货处理“同意退货”，退款金额“***”。处理意见“同意”。
s=firefox.find_element_by_xpath("//td/font[6]").text
print(s)
l="订单总额:￥ "
r="$"
s1=reGetString(s,l,r)
s1=int(s1)
firefox.find_element_by_id("refund_price").clear()
firefox.find_element_by_id("refund_price").send_keys(s1)
firefox.find_element_by_id("re_refund_info").send_keys("同意")
#  2.提交处理结果。
firefox.find_element_by_xpath("//button").click()
firefox.quit()

# 3.回到前台界面，点击“用户中心”，退货申请界面，查看退款成功"
firefox=openB(url)
login(firefox,user,password)
firefox.find_element_by_link_text("用户中心").click()
firefox.find_element_by_link_text("退货申请").click()
firefox.find_element_by_xpath("//div[@class='pull-right']/input").send_keys(orderID)
firefox.find_element_by_xpath("//button[@class='btn btn-small btn-primary']").click()
a=firefox.find_element_by_xpath("//tr/td[4]").text

if a == "退款成功":
    writeLog("%s 测试通过" % testCase)
else:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()